package com.zs.studentmanager.controller;

import com.zs.studentmanager.common.ResponseCodeEnum;
import com.zs.studentmanager.common.Result;
import com.zs.studentmanager.entity.vo.EchartsSeriesVo;
import com.zs.studentmanager.service.StudentScoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 周小白
 * @date: 2024-01-26 17:26
 **/
@RestController
@RequestMapping("/census")
@Tag(name = "统计数据接口")
public class CensusController {

    private final StudentScoreService studentScoreService;

    public CensusController(StudentScoreService studentScoreService) {
        this.studentScoreService = studentScoreService;
    }


    /**
     * 获取统计数据
     * @param courseId 课程id
     * @param gradeClassId 班级id
     * @return 统计数据
     */
    @GetMapping("/getCensusData")
    @Operation(summary = "获取统计数据")
    public Result getCensusData(@RequestParam(value = "courseId") Integer courseId,
                                @RequestParam(value = "gradeClassId") Integer gradeClassId){
        if (courseId == null || gradeClassId == null){
            return Result.fail(ResponseCodeEnum.NO_PARAM);
        }

        List<EchartsSeriesVo> list = studentScoreService.getCensusData(courseId, gradeClassId);
        if (list == null){
            return Result.fail(ResponseCodeEnum.SYSTEM_ERROR);
        }


        return Result.success(list);
    }


}
